import {
    fetchSystemStatus as apiFetchSystemStatus,
} from '../services/api'; // 引入 API

const system = {
    namespaced: true, // 启用命名空间
    state() {
        return {
            systemStatus: 'Unknown', // 存储系统状态
            performanceMetrics: [], // 存储性能指标
            roles: [], // 新增 roles 状态
        };
    },
    mutations: {
        SET_SYSTEM_STATUS(state, status) {
            state.systemStatus = status;
        },
        UPDATE_PERFORMANCE_METRICS(state, metrics) {
            state.performanceMetrics = metrics;
        },
    },
    actions: {
        fetchSystemStatus({ commit }) {
            return apiFetchSystemStatus().then(response => {
                commit('SET_SYSTEM_STATUS', response.data.status);
                // 这里可以添加提示信息
            }).catch(() => {
                // 处理错误提示
            });
        },
    },
    getters: {
        systemStatus: (state) => state.systemStatus,
        performanceMetrics: (state) => state.performanceMetrics,
        systemRoles(state) {
            return state.roles;
        },
    },
};

export default system;